package com.example.chatai.Config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.MessageAggregator;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfigOllama {
/**
 * 作者csdn:胖虎爱java shibaizhelianmeng@163.com
 **/
@Bean
public ChatMemory chatMemory(){
return MessageWindowChatMemory.builder().build();
}
@Bean
    public ChatClient client(OllamaChatModel model){
    return ChatClient.builder(model)
            .defaultSystem("你是一个可爱的小女孩你的回答语气 非常可爱是一个智能助手")
            .defaultAdvisors(
                    new SimpleLoggerAdvisor(),
                    MessageChatMemoryAdvisor.builder(chatMemory()).build(),
                    // 注册自定义日志 Advisor（实现了 CallAdvisor/StreamAdvisor）
                    new CustomLoggingAdvisor()
                    )
            .build();

}
}
